package com.goldgov.statistics.indexchar.web;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.branchCircle.service.Attention;
import com.goldgov.branchCircle.service.AttentionQuery;
import com.goldgov.branchCircle.service.AttentionService;
import com.goldgov.branchCircle.service.BranchCircle;
import com.goldgov.branchCircle.service.BranchCircleQuery;
import com.goldgov.branchCircle.service.BranchCircleService;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.utils.DateUtil;
import com.goldgov.utils.PropertyUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
/**
 * 2018年12月版本
 * @author liziwen
 *
 */
@RestController
@RequestMapping("/workbench/statistics/branchcirclechart")
@Api("支部圈统计接口")
public class BranchCircleCharController {

	@Autowired
	private AttentionService attentionService;
	@Autowired
	private BranchCircleService branchCircleService;
	
	@GetMapping("/getAttentionRank")
	@ApiOperation(value = "支部圈关注排行", notes = "支部圈关注排行")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchTreePath", value = "机构路径", paramType = "query")})
	public JsonQueryObject<Attention> getAttentionRank(@ApiIgnore AttentionQuery query,HttpServletRequest request,HttpServletResponse response) throws Exception {
		List<Attention> list=attentionService.getAttentionRank(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	
	
	@GetMapping("/getBranchCircleOrgRank")
	@ApiOperation(value = "支部圈发布数机构排行", notes = "支部圈发布数机构排行")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchTreePath", value = "机构路径", paramType = "query")})
	public JsonQueryObject<BranchCircle> getBranchCircleOrgRank(@ApiIgnore BranchCircleQuery query,HttpServletRequest request,HttpServletResponse response) throws Exception {
		List<BranchCircle> list=branchCircleService.getBranchCircleOrgRank(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	@GetMapping("/countChildOrgBranch")
	@ApiOperation(value = "下级机构所有人支部圈发布数", notes = "下级机构所有人支部圈发布数")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchOrgID", value = "机构ID", paramType = "query"),
	 @ApiImplicitParam(name = "searchBeginTime", value = "开始日期", paramType = "query"),
	 @ApiImplicitParam(name = "searchEndTime", value = "结束日期", paramType = "query"),
	 @ApiImplicitParam(name = "serarchNextNum", value = "下级机构数量", paramType = "query")})
	public JsonQueryObject<BranchCircle> countChildOrgBranch(@ApiIgnore BranchCircleQuery query,HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (!PropertyUtil.objectNotEmpty(query.getSearchBeginTime())&&!PropertyUtil.objectNotEmpty(query.getSearchEndTime())) {
			//取得当前年
			int year=DateUtil.getYear(new Date());
			query.setSearchBeginTime(year+"-01");
		}
		List<BranchCircle> list=branchCircleService.countChildOrgBranch(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
}
